import datetime
from sqlite3 import IntegrityError
from peewee import *
from service.das.data_map_das import DataDictionaryDas


class DataDictionaryService:

    # 增加数据字典项
    def add_dictionary_item(
        self, dict_key: str, dict_value: str, dict_desc: str = None
    ):
        print(
            f"查看结果dict_key:{dict_key},dict_key:{dict_value},dict_desc:{dict_desc}"
        )
        try:
            dataMapDas = DataDictionaryDas()
            dataMapDas.add_dictionary_item(dict_key, dict_value, dict_desc)
            print(f"字典项 {dict_key} 已添加成功。")
        except IntegrityError:
            print(f"字典键 {dict_key} 已存在，无法重复添加。")

    # 更新数据字典项
    def update_dictionary_item(
        self,
        dict_key: str,
        dict_value: str,
        dict_desc: str = None,
    ):
        try:
            dataMapDas = DataDictionaryDas()
            dataMapDas.add_dictionary_item(dict_key, dict_value, dict_desc)
            print(f"字典项 {dict_key} 已更新成功。")
        except DoesNotExist:
            print(f"字典键 {dict_key} 不存在，无法更新。")

    # 查询所有数据字典项
    def get_all_items(self):
        dataMapDas = DataDictionaryDas()
        return dataMapDas.get_all_items()
